package com.scap.dfs.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;




import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.scap.dfs.dao.DepartmentDao;
import com.scap.dfs.model.Department;
import com.scap.dfs.model.DepartmentPK;
import com.scap.dfs.service.DepartmentService;

@Controller
@RequestMapping (value="/department")
public class DepartmentController{

	
	@Autowired
	DepartmentService departmentService;
	
	@RequestMapping(value="")
	public ModelAndView view(HttpServletRequest request) {
		 System.out.println("Sawaddee ");
		 System.out.println("-------------------------------------------------");
		 System.out.println("Test add Department");
		 Department department = new Department();
		 DepartmentPK departmentPK = new DepartmentPK();
		 departmentPK.setCode("001");
		 departmentPK.setHospitalCode("011");
		 department.setId(departmentPK);
		 department.setActive("1");
		 department.setDefaultLocationCode("SCAP solution Payathai");
		 department.setDescription("Hospital for programer who crazy when doing DF project");
		 department.setGlCode("000000");
		 department.setHospitalUnitCode("0111");
		 department.setUserId("000001");
		 System.out.println("Result = "+departmentService.addDepartment(department));
		 
		 department = new Department();
		 departmentPK = new DepartmentPK();
		 departmentPK.setCode("002");
		 departmentPK.setHospitalCode("011");
		 department.setId(departmentPK);
		 department.setActive("1");
		 department.setDefaultLocationCode("ASAP solution Payathai");
		 department.setDescription("Hospital for DBA who crazy when doing DF project");
		 department.setGlCode("000000");
		 department.setHospitalUnitCode("0111");
		 department.setUserId("000001");
		 System.out.println("Result = "+departmentService.addDepartment(department));
		 
		 System.out.println("-------------------------------------------------");
		 System.out.println("Test Update Department");
		 departmentPK = new DepartmentPK();
		 departmentPK.setCode("001");
		 departmentPK.setHospitalCode("011");
		 department = new Department();
		 department.setId(departmentPK);
		 department.setDescription("New hospital for who crazy to doing springMVC and Hibernate");
		 departmentService.updateDepartment(department);
		 
		 System.out.println("-------------------------------------------------");
		 System.out.println("Test Find by PK");
		 departmentPK = new DepartmentPK();
		 departmentPK.setCode("001");
		 departmentPK.setHospitalCode("011");
		 department = departmentService.getDepartmentById(departmentPK);
		 System.out.println("Result from getById : ");
		 System.out.println(department.toString());
		 
		 
		 System.out.println("-------------------------------------------------");
		 System.out.println("Test getList()");
		 List<Department> departmentList = departmentService.getDepartmentList();
		 System.out.println("List result : ");
		 for(Department d: departmentList){
		 System.out.println(d.toString());
		 }
	
		 
		 
		 System.out.println("-------------------------------------------------");
		 System.out.println("Test getDepartmentListPerPage(int amount, int page,String orderByColumnName,String ascOrDesc)");
		 departmentList = departmentService.getDepartmentListPerPage(2, 1, "id.code", "asc");
		 System.out.println("List result : ");
		 for(Department d: departmentList){
		 System.out.println(d.toString());
		 }
		 
		 System.out.println("-------------------------------------------------");
		 System.out.println("Test findByAttribute(department)");
		 department = new Department();
		 department.setId(new DepartmentPK());
		 department.setHospitalUnitCode("0111");
		 department.setActive("1");
		 department.getId().setCode("001");
		 departmentList = departmentService.getDepartmentListByAttribute(department);
		 System.out.println("List result : ");
		 for(Department d: departmentList){
		 System.out.println(d.toString());
		 }
		 
		 System.out.println("-------------------------------------------------");
		 System.out.println("Test findByAttributePerPage(Department department, int amount,int page,String orderByColumnName,String ascOrDesc)");
		 department = new Department();
		 department.setId(new DepartmentPK());
		 department.setHospitalUnitCode("0111");
		 department.setActive("1");
		 departmentList = departmentService.getDepartmentListByAttributePerPage(department,1,1,"id.code","desc");
		 System.out.println("List result : ");
		 for(Department d: departmentList){
		 System.out.println(d.toString());
		 }
		 
		 
		 System.out.println("-------------------------------------------------");
		 System.out.println("Test Delete Department");
		 departmentPK = new DepartmentPK();
		 departmentPK.setCode("001");
		 departmentPK.setHospitalCode("011");
		 departmentService.deleteDepartment(departmentPK);
		 
		 return new ModelAndView("account/index");
	}

	
	public ModelAndView insert(HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}

	
	public ModelAndView update(HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}

	
	public ModelAndView delete(HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}

	
	public ModelAndView index() {
		// TODO Auto-generated method stub
		return null;
	}

	
	public ModelAndView index(HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}

	public ModelAndView search(HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}

	

}
